﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    public static GameManager Instence = null;
    public ScrollRect scrollRect;
    public Text messageText;
    public InputField fieldText;
    public Button sendBtn;

    private void Awake()
    {
        Instence = this;
    }

    private void Start()
    {
        messageText.text = "";
        sendBtn.onClick.AddListener(OnSendMessage);
    }

    void OnSendMessage()
    {
        string str = fieldText.text;
        if (string.IsNullOrEmpty(str)) return;
        bool state = SocketClientManager.OnSendToServer(str);
        if (state)
        {
            fieldText.text = "";
            messageText.text += "我=>: " + str + "\n";
            scrollRect.verticalScrollbar.value = 0;
        }
    }

    public void SetText(string msg)
    {
        messageText.text += "服务端: " + msg + "\n";
        scrollRect.verticalScrollbar.value = 0;
    }
}
